/*自定义增加规格*/
function addSpec(id) {
    var diyspec = $('#diyspec' + id);
    var diyspec_val = $.trim(diyspec.val());
    if (diyspec_val.length > 0) {
        var all_inputs = $('#goods-format-prod').find('input[type="checkbox"]');
        var nextStep = 0;
        $.each(all_inputs, function(i) {
            if ($(this).val() == diyspec_val) {
                nextStep++;
            }
        });
        if (nextStep > 0) {
            diyspec.val('');
            alert('规格值重复，请重新输入！');
            return;
        }
        var diy_str = diyspec.parent('li').prev('li').children('input').attr('id');
        var diy_id = parseInt(diy_str.replace(/\D/g, ''));
        ++diy_id;
        var new_spec = $('<li><input id="spec_id_' + diy_id + '" type="checkbox" value="' + diyspec_val + '" name="spec_name[spec_' + id + '][]"><label for="spec_id_' + diy_id + '">' + diyspec_val + '</label></li>');
        diyspec.parent('li').before(new_spec);
        diyspec.parent('li').before('&nbsp;');
        diyspec.val('');
    } else {
        window.alert('自定义项不能为空');
    }
}

/*添加店铺分类*/
function add_sgcategory() {
    var sgcategory = $('.sgcategory').eq(0);
    $(".sgcategory:last").after(sgcategory.clone());
}

/*删除图片*/
function drop_image(goods_file_id) {
    if (confirm(lang.uploadedfile_drop_confirm)) {
        var url = SITE_URL + '/index.php?app=my_goods&act=drop_image';
        $.getJSON(url, {
            'id': goods_file_id
        }, function(data) {
            if (data.done) {
                $('*[file_id="' + goods_file_id + '"]').remove();
                set_cover($("#goods_images li:first-child").attr('file_id'));
            } else {
                alert(data.msg);
            }
        });
    }
}